package com.graduation.springbootinit.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.graduation.springbootinit.mapper.RegionDictMapper;
import com.graduation.springbootinit.model.entity.ShopPart.RegionDict;
import com.graduation.springbootinit.service.RegionDictService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class RegionDictServiceImpl implements RegionDictService {

    @Resource
    private RegionDictMapper regionDictMapper;

    @Override
    public List<RegionDict> listProvinces() {
        return regionDictMapper.listProvinces();
    }

    @Override
    public List<RegionDict> listCities(String provinceCode) {
        return regionDictMapper.listByParentCode(provinceCode);
    }

    @Override
    public List<RegionDict> listDistricts(String cityCode) {
        return regionDictMapper.listByParentCode(cityCode);
    }

    @Override
    public RegionDict getByCode(String code) {
        QueryWrapper<RegionDict> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("code", code);
        return regionDictMapper.selectOne(queryWrapper);
    }
} 